home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.03 Mar 93 / CleanUpFolders / CleanUpFolders.c next >
Encoding:
C/C++ Source or Header  |  1992-10-17  |  3.2 KB  |  123 lines  |  [TEXT/KAHL]

  1. /*****************************************************
  2.  * CleanUpFolders
  3.  *
  4.  * A little app to clean up all folders' windows
  5.  * starting with the one that this app is in an
  6.  * continuing recursively downwards.
  7.  *
  8.  * Mike Scanlin  17 Oct 1992
  9.  ****************************************************/
  10.  
  11. #define kFolderBit            (1 << 4)
  12. #define kZoomBit            0x0020
  13. #define kOpenTriangleBit    0x0010
  14. #define kViewMask            0xFF00
  15. #define kViewByName            0x0200
  16.  
  17. void main(void);
  18. void CleanUpAFolder(long theDrDirID);
  19. void EnumerateCatalog(long dirID);
  20.  
  21. CInfoPBRec        theCPB;
  22. Str255            theName;
  23. Rect            theRect;
  24. short            hOffset, vOffset;
  25.  
  26.  
  27. /*****************************************************
  28.  * main
  29.  * 
  30.  * Clean up the directory that this app is residing
  31.  * in and then all of the directories contained within
  32.  * this directory recursively. Put this app in the 
  33.  * root directory of a volume and launch it to clean 
  34.  * up the entire volume.
  35.  ****************************************************/
  36. void main()
  37. {
  38.     long        dirID;
  39.     short        vRefNum;
  40.     
  41.     /* Set the initial directory's size and position */
  42.     SetRect(&theRect, 2, 40, 2+228, 40+165);
  43.     
  44.     /* Set the offset for each child directory */
  45.     hOffset = 16;
  46.     vOffset = 16;
  47.     
  48.     /* Find out where this app is located */
  49.     HGetVol(&theName, &vRefNum, &dirID);
  50.  
  51.     theCPB.dirInfo.ioVRefNum = vRefNum;
  52.     theCPB.dirInfo.ioNamePtr = theName;
  53.     
  54.     /* First, clean up the current directory */
  55.     theCPB.hFileInfo.ioFDirIndex = -1;
  56.     theCPB.dirInfo.ioDrDirID = dirID;
  57.     PBGetCatInfo(&theCPB, FALSE);
  58.     CleanUpAFolder(theCPB.dirInfo.ioDrParID);
  59.     
  60.     /* Now clean up all child directories */
  61.     EnumerateCatalog(dirID);
  62. }
  63.  
  64.  
  65. /*****************************************************
  66.  * CleanUpAFolder
  67.  * 
  68.  * Given a directory ID, this will unzoom the
  69.  * window, size and position the window, close the
  70.  * "triangle" and set the view to View by Name.
  71.  ****************************************************/
  72. void CleanUpAFolder(long theDrDirID)
  73. {
  74.     theCPB.dirInfo.ioDrDirID = theDrDirID;
  75.     theCPB.dirInfo.ioDrUsrWds.frRect = theRect;
  76.     /* clear the zoomed bit, the "open triangle bit"
  77.      * and the view; leave the other bits alone
  78.      * because we don't know what they're for.
  79.      */
  80.     theCPB.dirInfo.ioDrUsrWds.frView &=
  81.         ~kViewMask - kZoomBit - kOpenTriangleBit;
  82.     /* set the view to View by Name */
  83.     theCPB.dirInfo.ioDrUsrWds.frView |= kViewByName;
  84.     PBSetCatInfo(&theCPB, FALSE);
  85. }
  86.  
  87.  
  88. /*****************************************************
  89.  * EnumerateCatalog
  90.  *
  91.  * Given a directory ID to start with, this calls
  92.  * CleanUpAFolder once for every directory within
  93.  * the given start directory. On entry it offsets
  94.  * theRect down and to the right; on exit it offsets
  95.  * it up and to the left.
  96.  ****************************************************/
  97. void EnumerateCatalog(long dirID)
  98. {
  99.     long        tempDir;
  100.     short        index;
  101.     OSErr        myErr;
  102.     
  103.     OffsetRect(&theRect, hOffset, vOffset);
  104.  
  105.     index = 1;
  106.     do {
  107.         theCPB.hFileInfo.ioFDirIndex = index;
  108.         theCPB.dirInfo.ioDrDirID = dirID;
  109.         myErr = PBGetCatInfo(&theCPB, FALSE);
  110.         if (myErr == noErr) {
  111.             if (theCPB.hFileInfo.ioFlAttrib & kFolderBit) {
  112.                 tempDir = theCPB.dirInfo.ioDrDirID;
  113.                 CleanUpAFolder(dirID);
  114.                 EnumerateCatalog(tempDir);
  115.                 myErr = noErr;
  116.             }
  117.         }
  118.         index++;
  119.     } while (myErr == noErr);
  120.  
  121.     OffsetRect(&theRect, -hOffset, -vOffset);
  122. }
  123.